package cn.jbolt.ai.app.controller;

import cn.jbolt.ai.app.entity.AiAppConfig;
import cn.jbolt.ai.app.service.AiAppConfigService;
import cn.jbolt.ai.app.vo.AiConfigVO;
import cn.jbolt.util.Result;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("/aiAppConfig")
@Tag(name = "ai应用配置管理Controller")
public class AiAppConfigController {

    @Autowired
    private AiAppConfigService aiAppConfigService;


    @Operation(summary = "修改app的配置,全修改", description = "修改app的配置")
    @PostMapping("/updateConfig")
    public Result updateConfig(@RequestBody AiAppConfig aiAppConfig) {
        return aiAppConfigService.update(aiAppConfig.getLinkType(), aiAppConfig.getLinkId(),
                 aiAppConfig.getConfigValue());
    }
    @Operation(summary = "修改app的配置,只修改指定key的配置", description = "修改app的配置")
    @PostMapping("/updateConfigByKey")
    public Result updateConfigByKey(@RequestBody AiAppConfig aiAppConfig) {
        return aiAppConfigService.updateConfigByKey(aiAppConfig.getLinkType(), aiAppConfig.getLinkId(),
                aiAppConfig.getConfigKey(), aiAppConfig.getConfigValue());
    }

    @Operation(summary = "修改app的配置,只修改指定key的配置,批量修改", description = "修改app的配置")
    @PostMapping("/updateConfigListByKeyList")
    public Result updateConfigListByKeyList(@RequestBody AiConfigVO vo) {
        return aiAppConfigService.updateConfigByBatch(vo);
    }


    @Operation(summary = "根据关联类型,关联id,配置key三个条件获取相关的配置", description = "根据关联类型,关联id,配置key三个条件获取相关的配置")
    @GetMapping("/getConfigByCondition")
    public Result getConfigByCondition(String linkType, Long linkId,String configKey) {
        return aiAppConfigService.getConfigByCondition(linkType, linkId,configKey);
    }

    @Operation(summary = "根据关联类型,关联id,多个配置key三个条件获取相关的配置", description = "根据关联类型,关联id,多个配置key三个条件获取相关的配置")
    @PostMapping("/getConfigListByCondition")
    public Result getConfigListByCondition(@RequestBody AiConfigVO vo) {
        return aiAppConfigService.getConfigListByCondition(vo.getLinkType(), vo.getLinkId(),vo.getConfigKeyList());
    }
}
